
import 'package:situation/domain/common/result.dart';
import 'package:situation/domain/intell/IntellArea.dart';
import 'package:situation/domain/intell/IntellCategory.dart';
import 'package:situation/domain/intell/intell_history_dto.dart';
import 'package:situation/domain/intell/intell_time_line.dart';
import 'package:situation/domain/user/task.dart';
import 'package:situation/shared/util/util_http.dart';

class IntellRequest {

  // 获取情报分类
  static Future<List<IntellCategory>> getIntellCategory() async {
    var response = await UtilHttp().get(
      '/qingbaoType/',
    );
    return response['data']['records']
        .map<IntellCategory>((item) => IntellCategory.fromJson(item))
        .toList();
  }
  // 获取上报单位
  static Future<List<IntellArea>> getAreaSubByAreaCode(code) async {
    var response = await UtilHttp().get(
      '/business/sysAreaSubordination/getAreaSubByAreaCode?areaCode=' + code,
    );
    return response['data']
        .map<IntellArea>((item) => IntellArea.fromJson(item))
        .toList();
  }
  // 获取我上报的情报
  static Future<List<IntellHistoryDto>> getMyIntell() async {
    var response = await UtilHttp().get(
      '/qingbao/getMyQingbaoList',
    );
    return response['data']['records']
        .map<IntellHistoryDto>((item) => IntellHistoryDto.fromJson(item))
        .toList();
  }

  // 上报情报
  static Future<Result> publishIntell(data) async {
    var response = await UtilHttp().post(
      '/qingbao',
      data: data
    );
    return Result.fromJson(response);
  }

  // 上报情报
  static Future<Result> upQingbaoInfo(data) async {
    var response = await UtilHttp().post(
      '/qingbaoInfo',
      data: data
    );
    return Result.fromJson(response);
  }
  static Future getIntellDetail(id) async {
    var response = await UtilHttp().get(
      '/qingbao/' + id,
    );
    return response;
  }


  static Future<List<Task>> getMyTaskList(current,size,status) async {
    var response = await UtilHttp().get(
      '/task/getMyTaskList?current=${current}&size=${size}&status=${status}' ,
    );
    return response['data']['records']
        .map<Task>((item) => Task.fromJson(item))
        .toList();
  }

  // 情报资讯
  static Future<List<IntellHistoryDto>> getMyAroundQingbao(lat,lon,radius) async {
    var response = await UtilHttp().get(
      '/qingbao/getMyAroundQingbao?lon=${lon}&lat=${lat}&radius=${radius}' ,
    );
    return response['data']['records']
        .map<IntellHistoryDto>((item) => IntellHistoryDto.fromJson(item))
        .toList();
  }

  // 情报时间轴
  static Future<List<IntellTimeLine>> getTimeLineList(id,current,size) async {
    var response = await UtilHttp().get(
      '/qingbaoInfo/getTimeLineList?qingbaoId=${id}&current=${current}&size=${size}',
    );
    return response['data']['records']
        .map<IntellTimeLine>((item) => IntellTimeLine.fromJson(item))
        .toList();
  }

  static Future getTaskDetail(id) async {
    var response = await UtilHttp().get(
      '/task/getMyTaskDetail?taskId=' +
          id,
    );
    return response['data'];
  }

  // 更新任务状态
  static Future<Result> updateTaskStatus(data) async {
    var response = await UtilHttp().post(
        '/task/updateMyTaskStatus',
        data: data
    );
    return Result.fromJson(response);
  }


}